package com.example.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.datasource.TargetDataSource;
import com.example.mapper.TodoMapper;
import com.example.pojo.Todo;

@Service  
public class TodoService {  
      
    @Autowired  
    private TodoMapper todoMapper;  
  
    public Todo select(int id) {  
        return todoMapper.select(id);  
    }  
    
    @TargetDataSource(name = "springboot1")
    public Todo select1(int id) {  
        return todoMapper.select(id);  
    }  
    
    @TargetDataSource(name = "springboot2")
    public Todo select2(int id) {  
        return todoMapper.select(id);  
    }  
  
    public int insert(String title, String details) {  
        Todo todo = new Todo();  
        todo.setTitle(title);  
        todo.setDetails(details);  
        todo.setFinished(1);  
        todoMapper.insert(todo);  
          
        return todo.getId();  
    }  
    
    @TargetDataSource(name = "springboot1")
    public int insert1(String title, String details) {  
        Todo todo = new Todo();  
        todo.setTitle(title);  
        todo.setDetails(details);  
        todo.setFinished(1);  
        todoMapper.insert(todo);  
          
        return todo.getId();  
    }
    
    @TargetDataSource(name = "springboot2")
    public int insert2(String title, String details) {  
        Todo todo = new Todo();  
        todo.setTitle(title);  
        todo.setDetails(details);  
        todo.setFinished(1);  
        todoMapper.insert(todo);  
          
        return todo.getId();  
    }
  
}